/***********************************************************************************************************************************
 * Name:	ActiveDirectory.BBA.sql
 * Author:	Frank Figearo (frank@sqlnerd.me)
 * Summary:	Create Linked Servers for Active Directory. Sample query.
 */
SET IMPLICIT_TRANSACTIONS OFF; WHILE 0 < @@TRANCOUNT ROLLBACK;
GO
EXEC sp_addlinkedserver 'ActiveDirectory1', 'Active Directory Service Interfaces', 'ADsDSOObject', 'BBA-ORL-VDC1';
EXEC sp_addlinkedserver 'ActiveDirectory2', 'Active Directory Service Interfaces', 'ADsDSOObject', 'BBA-ORL-VDC2';
GO
SELECT * FROM OPENQUERY(ActiveDirectory2, 'SELECT name, adsPath FROM ''LDAP://DC=BBAAviation,DC=net'' WHERE objectCategory = ''Person'' AND objectClass= ''user''');
GO